package utils

// 给出两个切片，比较这两个切片共有部分和特有部分
func CompareSlice[T comparable](a, b []T) (aOnly, bOnly, common []T) {
	aOnly, bOnly, common = make([]T, 0), make([]T, 0), make([]T, 0)
	aMap := make(map[T]bool)
	bMap := make(map[T]bool)
	for _, v := range a {
		aMap[v] = true
	}
	for _, v := range b {
		bMap[v] = true
	}
	for key := range aMap {
		_, have := bMap[key]
		if have {
			common = append(common, key)
		}
	}
	for key := range aMap {
		_, have := bMap[key]
		if !have {
			aOnly = append(aOnly, key)
		}
	}
	for key := range bMap {
		_, have := aMap[key]
		if !have {
			bOnly = append(bOnly, key)
		}
	}
	return
}
